<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>新增优惠券实体</title>
<script type="text/javascript" src="<%=path%>/projectjs/ImageFileUpload.js"></script>
<script type="text/javascript">
	function addEntity(obj){
		if (!iu1.validate()) {
			alert("您还有像素为：【"+iu1.need_add_pic_pixel.join(",")+"】的未激活图片要添加，请添加图片！");
			iu1.openAddImgFrame();
			return false;
		}
		if (!iu2.validate()) {
			alert("您还有像素为：【"+iu2.need_add_pic_pixel.join(",")+"】的已激活图片要添加，请添加图片！");
			iu2.openAddImgFrame();
			return false;
		}
		return validateCallback(obj, navTabAjaxDone);
	}
	
 //显示代金券
 function showValue(){
 
 if($("select#favourableTypeId option:selected").text() == '代金券') 
{
 $("#valueDiv").show();
 }else{
  $("#money").val('0');
  $("#valueDiv").hide();
 }
 }
 
 //显示提醒
  function showRemind(){
 if($("select#isRemind option:selected").val() == 1) 
{
 $("#remindDiv").show();
 }else{
   $("#remindManner").val(-1);
   $("#remindContent").val("");
   $("#remindTime").val("");
   $("#remindDiv").hide();
 }
 }
 
 function showReleasChannel(){
  if($("#classification option:selected").val() == 1){
 	$("select#releaseChannel > option")[1].selected="selected";
 	$("select#releaseChannel > option")[0].disabled="disabled";
 	$("select#releaseChannel > option")[2].disabled="disabled";
 	$("#amount").val("");
 	$("#amountDiv").hide();
  }else {
 	$("select#releaseChannel > option")[0].disabled="";
 	$("select#releaseChannel > option")[2].disabled="";
 	document.getElementById("amountDiv").show();
  }
 }
 //检查时间
 function checkTime(){
 usebegDate = document.getElementById("usebegDate").value.replaceAll("-","").replaceAll(" ","").replaceAll(":","");
 useendDate = document.getElementById("useendDate").value.replaceAll("-","").replaceAll(" ","").replaceAll(":","");
 applybegDate = document.getElementById("applybegDate").value.replaceAll("-","").replaceAll(" ","").replaceAll(":","");
 applyendDate = document.getElementById("applyendDate").value.replaceAll("-","").replaceAll(" ","").replaceAll(":","");
 validTimeFrom = document.getElementById("validTimeFrom").value.replaceAll(":","");
 validTimeTo = document.getElementById("validTimeTo").value.replaceAll(":","");
 if(useendDate < useendDate){
 alertMsg.error('使用期限：结束日期比开始日期小');
 return false;
 }else if(validTimeTo < validTimeFrom){
 alertMsg.error('可用时段：结束时间比开始时间小');
 return false;
 }else if(applyendDate < applybegDate){
 alertMsg.error('申请期限：结束日期比开始日期小');
 return false;
 }else{
 return true;
 }
 }
 String.prototype.replaceAll = function(s1,s2) { 
    return this.replace(new RegExp(s1,"gm"),s2); 
}
 
 function clearShops(){
 $("#shopCode").val("");
 $("#shopNames").val("");
 }
 

</script>

	</head>

	<body >
		<div class="pageContent">
			<form method="post"
				action="<%=path%>/favourableEntity/saveFavourableEntity.action"
				class="pageForm required-validate"
				onsubmit="return  addEntity(this);">
				<div class="pageFormContent " layoutH="56" >
					<fieldset>
					<p>
						<label>
							优惠券名：
						</label>
						<input name="favourableEntityVO.name" class="required" type="text"
							size="30" alt="请输入优惠券名" />

					</p>
					   <p>
						<label>
							编码：
						</label>
						<input name="favourableEntityVO.code"
							value="<s:property value="favourableEntityVO.code" />"
							  type="text" size="30" readonly="readonly"/>
					   </p>
					   <p>
						<label>
							优惠券类别：
						</label>
						<s:select list="favourableTypeList" listKey="id"
							listValue="favourableType"
							name="favourableEntityVO.favourableTypeId" class="required" onchange="return showValue();" id="favourableTypeId"></s:select>
					</p>
					<p>
						<label>
							是否最新：
						</label>

						<s:select name="favourableEntityVO.isNew"
							list="%{#{0:'否',1:'是'}}" listKey="key" listValue="value" ></s:select>
					</p>
					<p>
						<label>
							是否热门：
						</label>

						<s:select name="favourableEntityVO.isHot"
							list="%{#{0:'否',1:'是'}}" listKey="key" listValue="value" ></s:select>
					</p>
					<p>
						<label>
							是否推荐：
						</label>

						<s:select name="favourableEntityVO.isRecommend"
							list="%{#{0:'否',1:'是'}}" listKey="key" listValue="value" ></s:select>
					</p>
					<p  id="valueDiv" >
						<label>
							代金金额：
						</label>
						<input name="favourableEntityVO.value" id="money"
							type="text" size="30" value="0" />

					</p>
					<p>
						<label>
							优惠券种类：
						</label>
						<s:select name="favourableEntityVO.classification"
							list="%{#{1:'专用型',0:'普惠制'}}" listKey="key" listValue="value" id="classification" onchange="showReleasChannel();"></s:select>
					</p>
					</fieldset>
					<fieldset>
						<legend>
							使用期限：
						</legend>
						<p>
						<label>
							优惠券开始申请时间：
						</label>
						<input name="favourableEntityVO.applyBegDate"
							value="<fmt:formatDate value="${favourableEntityVO.applyBegDate}" pattern="yyyy-MM-dd"/>"
							class="date" type="text" size="30" dateFmt="yyyy-MM-dd" minDate="%y-%M-%d" id="applybegDate"/>
						
					</p>
					<p>
						<label>
							优惠券结束申请时间：
						</label>
						<input name="favourableEntityVO.applyEndDate"
							value="<fmt:formatDate value="${favourableEntityVO.applyEndDate}" pattern="yyyy-MM-dd"/>"
							class="date" type="text" size="30" dateFmt="yyyy-MM-dd" id="applyendDate" minDate="%y-%M-%d"/>

					</p>
					<p>
						<label>
							优惠券开始使用时间：
						</label>
						<input name="favourableEntityVO.useBegDate"
							value="<fmt:formatDate value="${favourableEntityVO.useBegDate}" pattern="yyyy-MM-dd"/>"
							class="date" type="text" size="30" dateFmt="yyyy-MM-dd" minDate="%y-%M-%d" id="usebegDate"/>
						
					</p>
					<p>
						<label>
							优惠券结束使用时间：
						</label>
						<input name="favourableEntityVO.useEndDate"
							value="<fmt:formatDate value="${favourableEntityVO.useEndDate}" pattern="yyyy-MM-dd"/>"
							class="date" type="text" size="30" dateFmt="yyyy-MM-dd" id="useendDate" minDate="%y-%M-%d"/>

					</p>
					</fieldset>
					<fieldset>
						<legend>
							可用时段：
						</legend>

						<p>
							<label>
								开始：
							</label>
							<input name="favourableEntityVO.validTimeFrom" class="date"
								type="text required" dateFmt="HH:mm" size="30" id="validTimeFrom"/>
						</p>

						<p>
							<label>
								结束：
							</label>
							<input name="favourableEntityVO.validTimeTo" class="date"
								type="text required" dateFmt="HH:mm" size="30" id="validTimeTo"/>
						</p>
					</fieldset>
					<fieldset class="nowrap">
					<p>
						<label>
							是否手机使用验证：
						</label>

						<s:select name="favourableEntityVO.isAuthenByMoblie"
							list="%{#{1:'是',0:'否'}}" listKey="key" listValue="value" ></s:select>
					</p>
					<p>
						<label>
							是否到期提醒：
						</label>
						<s:select name="favourableEntityVO.isRemind"
							list="%{#{1:'是',0:'否'}}" listKey="key" listValue="value" id="isRemind" onchange="return showRemind();"></s:select>

					</p>
					<div id="remindDiv">
					<p>
						<label>
							到期多少天提醒：
						</label>
						<input name="favourableEntityVO.remindTime" 
							type="text" size="30" alt="请输入到期多少天提醒" fieldClass="digits" id="remindTime"/>
					</p>
					<p>
						<label>
							提醒方式：
						</label>
						<s:select name="favourableEntityVO.remindManner"
							list="%{#{-1:'请选择',1:'短信',0:'信息推送'}}" listKey="key" listValue="value" id="remindManner"></s:select>

					</p>
					<dl>
						<dt>
							提醒内容：
						</dt>
						<dd>
						<textarea name="favourableEntityVO.remindContent" cols="50" rows="4" id="remindContent"></textarea>
						<dd>
					</dl>
					</div>
					</fieldset>
					<fieldset class="nowrap">
					<dl>
						<dt>
							优惠券简要描述：
						</dt>
						<dd>
						<textarea name="favourableEntityVO.simpleDescription" cols="50" rows="4"></textarea>
						</dd>
					</dl>
					<dl>
						<dt>
							优惠券详情：
						</dt>
						<dd>
						<textarea name="favourableEntityVO.detail" cols="50" rows="4"></textarea>
						</dd>
					</dl>
					</fieldset>
					<div class="divider"></div>
					<div id="amountDiv">
					<p>
						<label>
							预发送数量：
						</label>
						<input name="favourableEntityVO.amount" 
							type="text" size="30" alt="请输入预发送数量" fieldClass="digits" id="amount"/>
					</p>
					</div>
				<p>
						<label>
							发送渠道：
						</label>
						<s:select name="favourableEntityVO.releaseChannel"
							list="%{#{0:'全部',1:'商家发送',2:'自主申请'}}" listKey="key" listValue="value" id="releaseChannel"></s:select>
					</p>
					
					<div class="divider"></div>

					<p>
						<label>
							商户：
						</label>
						
						<input name="favourableEntityVO.customerId" value="${SESSION_USER.customer==null?'':(SESSION_USER.customer.id)}"
							type="hidden" id="customerId">
						
						<input name="favourableEntityVO.customerName" type="text" size="30"
							value="${SESSION_USER.customer==null?'':(SESSION_USER.customer.name)}" readonly="readonly"/>
						
						<c:if test="${SESSION_USER.customer==null}">
						<a class="btnLook"
							href="<%=path%>/customer/listCustomer.action?searchType=favourableEntity"
							lookupGroup="favourableEntityVO" onclick="return clearShops();">选择</a>
						</c:if>
					</p>
					<p>
						<label>
							店面：
						</label>
						<input name="favourableEntityVO.shopCode" value="" type="hidden" id="shopCode">
						<textarea name="favourableEntityVO.shopNames" id="shopNames" readonly="readonly"></textarea>
						<a class="btnLook"
							href="<%=path%>/shop/listShop.action?templateId=-2&customerId={customerId}"
							lookupGroup="favourableEntityVO" warn="请先选择商户">选择</a>
					</p>
					<div class="divider"></div>
				<p style="width: 98%">
					<label>未激活图片：</label>
					<a class="button" onclick="openAddImgFrame(1);"><span>添加图片</span></a>
					<a id="add_pic_a_id1" class="btnAttach" href="<%=path%>/jsp/common/image_file_upload.jsp" lookupGroup="" width="560" height="300" style="display: none"></a>
					<div class="divider" style="border:0"></div>
					<div id="pic_need_add_pixel_div1"></div>
					<div class="divider" style="border:0"></div>
					<div id="pic_content_div1" style="float: none;width:auto;padding-left: 150px;"></div>
				</p>
				<div class="divider"></div>
				<p style="width: 98%">
					<label>已激活图片：</label>
					<a class="button" onclick="openAddImgFrame(2);"><span>添加图片</span></a>
					<a id="add_pic_a_id2" class="btnAttach" href="<%=path%>/jsp/common/image_file_upload.jsp" lookupGroup="" width="560" height="300" style="display: none"></a>
					<div class="divider" style="border:0"></div>
					<div id="pic_need_add_pixel_div2"></div>
					<div class="divider" style="border:0"></div>
					<div id="pic_content_div2" style="float: none;width:auto;padding-left: 150px;"></div>
				</p>
				</div>
				<div class="formBar">
					<ul>
						<li>
							<div class="buttonActive">
								<div class="buttonContent">
									<button type="submit" onclick="return checkTime();"> 
										保存 
									</button>
								</div>
							</div>
						</li>
						<li>
							<div class="button">
								<div class="buttonContent">
									<button type="button" class="close">
										取消
									</button>
								</div>
							</div>
						</li>
					</ul>
				</div>
			</form>
		</div>
<script type="text/javascript">
var iu1 = new ImageUpload("","favourable","1","${pageContext.request.contextPath}","favourableEntityVO.nonactivatedPic");
var iu2 = new ImageUpload("","favourable","2","${pageContext.request.contextPath}","favourableEntityVO.activatedPic");
</script>
	</body>
</html>